package com.sl.happying.reading.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.*;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

import io.swagger.annotations.ApiModelProperty;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

/**
 * 小说信息表
 */
@Table
@Entity
public class Novel implements Serializable{

    private static final long serialVersionUID = -717672218353371778L;

    @Id
    @GeneratedValue
    private int novelId;

    private String novelName;

    private String author;

    private Date uploadTime;

    @OneToMany(targetEntity=Chapter.class, cascade=CascadeType.ALL, fetch = FetchType.EAGER)
    @Fetch(FetchMode.JOIN)
    //updatable=false很关键，如果没有它，在级联删除的时候就会报错(反转的问题)
    @JoinColumn(name="novelId", updatable=false)
    private List<Chapter> chapters = new ArrayList<Chapter>();

    public Novel(){

    }

    public Novel(String novelName, Date uploadTime) {
        this.novelName = novelName;
        this.uploadTime = uploadTime;
    }

    public void setNovelId(int novelId) {
        this.novelId = novelId;
    }

    public String getNovelName() {
        return novelName;
    }

    public String getAuthor() {
        return author;
    }

    public Date getUploadTime() {
        return uploadTime;
    }

    public int getNovelId() {
        return novelId;
    }

    public void setNovelName(String novelName) {
        this.novelName = novelName;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public void setUploadTime(Date uploadTime) {
        this.uploadTime = uploadTime;
    }

    public List<Chapter> getChapters() {
        return chapters;
    }

    public void setChapters(List<Chapter> chapters) {
        this.chapters = chapters;
    }

    /*@Override
    public String toString() {
        return "Novel{" +
                "novelId=" + novelId +
                ", novelName='" + novelName + '\'' +
                ", author='" + author + '\'' +
                ", uploadTime=" + uploadTime +
                ", chapters=" + chapters +
                '}';
    }*/
}
